﻿using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;

namespace Corina.Converters.Silverlight
{
    public class SelectedIndexToCornerRadiusConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int index = (int)value;
            if (index == 0)
            {
                double[] radius = parameter.ToString().Split('-').Select(t => System.Convert.ToDouble(t)).ToArray();
                return new CornerRadius(radius[0], radius[1], radius[2], radius[3]);
            }
            else
            {
                return new CornerRadius(0);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return 0;
        }
    }
}
